<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>百商汇</title>
	<meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0,minimum-scale = 1.0,user-scalable = no,width = device-width">
	<meta name="format-detection" content="telephone=no" />
	<link rel="stylesheet" type="text/css" href="../csses/withdrawal.css">
	<script type="text/javascript">
		if(location.pathname != '/h5/views/login.html' && !sessionStorage.token){
			window.location.href = 'login.html';
		}
	</script>
</head>
<body>
	<div class="withdrawal_title">
		提现
		<img src="../image/back.png" onclick="goBack()">
		<a href="./withdrawalList.html" class="withdrawalList">提现列表</a>
	</div>
	<div class="withdrawal_box">
		<ul class="ul">
			<li class="amount">
				<span>金&nbsp;&nbsp;额</span>
				<input type="text" placeholder="请输入您要提取的金额(100的整数倍)" class="input"></input>
			</li>
			<li class="bankCard">
				<span>银 行 卡</span>
				<input type="text" placeholder="请选择您已绑定的银行卡" readonly="true"></input>
				<div class="choose">
					<img src="../image/bottom.png">
				</div>
			</li>
			<li class="payPsw">
				<span>支付密码</span>
				<input type="password" placeholder="请输入百商汇支付密码" class="input"></input>
				<div class="choose">
					<img src="../image/psw.png">
				</div>
			</li>
			<li class="remarks">
				<span>备&nbsp;&nbsp;注</span>
				<input type="text" placeholder="请输入备注" class="input"></input>
			</li>
		</ul>
		<button class="submitBtn">确认</button>

		<div id="hidden_box">
			<ul>
				<li>请选择</li>
			</ul>
		</div>

		<div id="remindBox"></div>
	</div>

	<script type="text/javascript" src="../lib/flexible.js"></script>
	<script type="text/javascript" src="../lib/jquery-1.10.1.min.js"></script>
	<script type="text/javascript">
		function goBack(){
			window.history.back();
		}


		$('.input').focus(function(){
			this.select();
		});

		function remind(message){
			$('#remindBox').css('display','block').text(message);
			setTimeout(function(){
				$('#remindBox').css('display','none');
			},1500);
		}

		$.ajax({
			type : 'post',
			url : '/api/v1/bank/myCardList',
			data : {
				paramStr: "{'userName':'" + sessionStorage.userName + "','token':'" + sessionStorage.token + "'}"
			},
			dataType : 'json',
			timeout : 10000,
			success : function (data) {
				if(data.code == 200){
					var obj = JSON.parse(data.data);
					var myCardList = obj.myCardList;
					for(var i in myCardList){
						$('<li userBankId='+myCardList[i]["id"]+'></li>').addClass('content').text(myCardList[i].bank_name + '('+myCardList[i].bank_card.slice(myCardList[i].bank_card.length-4) +')').appendTo($('#hidden_box ul'));
					}
					$('.bankCard input').click(function(){
						$('#hidden_box').css('display','block');
						$('#hidden_box').click(function(){
							if(event.target.getAttribute('class') == 'content'){
								$('.bankCard input').val(event.target.textContent);
								sessionStorage.userBankId = event.target.getAttribute('userBankId');
								$('#hidden_box').css('display','none');
							}else{
								$('#hidden_box').css('display','none');
							}
						});
					});
				}
			},
			error : function (xhr,type,errorThrown){
				// alert('.....');
			}
		});

		$('.submitBtn').click(function(){
			var $withdrawalMoney = $('.amount input').val();
			var $payPassword = $('.payPsw input').val();
			var $memo = $('.remarks input').val();
			if($withdrawalMoney % 100 != 0 || !$withdrawalMoney || $withdrawalMoney == 0){
				remind('提现金额须为100的整数倍');
			}else if(!sessionStorage.userBankId){
				remind('请选择银行卡');
			}else if(!$payPassword){
				remind('请输入支付密码');
			}else if(sessionStorage.isVerify == 'false'){
				remind('只有实名认证用户才能在微信中提现');
			}else{
				$.ajax({
					type : 'post',
					url : '/api/v1/finance/transfer/withdrawl',
					data : {
						paramStr: "{'userName':'" + sessionStorage.userName + "','token':'" + sessionStorage.token + "','payPassword':'" + $payPassword +"','withdrawalMoney':'" + $withdrawalMoney +"','userBankId':'" + sessionStorage.userBankId +"','memo':'" + $memo + "'}"
					},
					dataType : 'json',
					timeout : 10000,
					success : function (data) {
						remind(data.message);
						if(data.code == 200){
							$('.submitBtn').attr('disabled',true).css('background','#ccc');
							setTimeout(function(){
								window.location.href = '../index1.html';
							},1500);
						}
					},
					error : function(xhr,type,errorThrown){
						// alert('...');
					}
				});
			}
		});
	</script>
</body>
</html>